<?php
use \yii\helpers\HtmlPurifier;
$this->registerJSFile('@web/js/count.js',['depends'=>['app\assets\AppAsset']]);
?>
<form action="?r=writing/index" id="nextque" method="post">
	<input type="hidden" name="page" value="<?=$page?>">
	<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
	<input name="usercheck" type="hidden" value="">
	<input type="hidden" name="post_type" value="">
	<input type="hidden" name="total-views" value="">
	<input type="hidden" name="first-view" value="">
	<input type="hidden" name="second-view" value="">
	<input type="hidden" name="third-view" value="">
</form>
<script>
    <?php
    $session = \Yii::$app->session;
    $session->open();
    $session['form']=3;/*判断是1.php还是3.php的第一方面，第二方面···*/
    ?>
    var isWay=<?php if($session['write_practice'])echo "true";else echo "false";?>;
	window.onload = function () {
		// 如果是方法练习，isWay为真,如果是非方法练习，就执行if里面的语句

		if (!isWay) {
			$(".add-note").remove();
			$(".form-control").prop("disabled",true);
		}
		if(isWay){
            var timeCount=new countTime({
                parent:"time-count",
                alert:"已经3分钟了哦",
                count:180
            });
            timeCount.init();
        }


		var $option=$("form.form input");
	    $('#next').click(function () {
	    	if (isWay) {
		    	var flag=true;
				if (!$option.eq(0).val()){
					flag=false;
				}
				if (!flag) {
					alert("请至少填写总主题");
					return false;
				}else{
					$("[name=total-views]").val($("#total-views3").val());
					$("[name=first-view]").val($("#first-view3").val());
					$("[name=second-view]").val($("#second-view3").val());
					$("[name=third-view]").val($("#third-view3").val());
					$("#nextque").submit();
				}
			}else{
				$("#nextque").submit();
			}
	    });



		var $submit_time=$("[name=post_type]").clone(true).attr("name","time");
		$submit_time.appendTo("#nextque");
		var t=0;
		//计时
		$.ajax({
			url: "?r=ajax/gettime&state=<?=$state;?>&token=<?=$token;?>",
			dataType: 'json',
			type: 'get',
			success: function (data) {
				var $time=$("i.fa-clock-o");
				var sec=data.time;          //初始时间，以秒为单位
				setInterval(
					function(){
						sec++;
						t++;
						$time.html(secToMin(sec));
						$submit_time.val(t);
					},1000);
			}
		});
	};
</script>
<div class="container">
	<div class="leadx row clearfix">
		<div class="col-xs-3 pull-left">
			<span>
				TPO<?=$write_content['class_num'];?> Writing <?=$write_content['class_name']?>
			</span>
		</div>
		<div class="col-xs-1 pull-left notebook">
			<a href="#"><span><i class="fa fa-pencil-square-o"></i> 笔记</span></a>
		</div>
		<div class="col-xs-1 pull-right">
			<span><i class="fa fa-clock-o"></i></span>
		</div>
	</div>
	<div class="write-wrap">
		<div class="write-info row"></div>
		<div class="col-xs-5 write-spe">
			<div class="write-que">
				<div class="que clearfix">
                    <div class="pull-left"><?php
                    if($write_content['class_name']=="综合写作")
                        echo "根据文章内容完成下表";
                    else
                        echo "由题目你能想到";
                    ?></div>
                    <div class="pull-right" id="time-count"></div>
                </div>
				<form class="form form-horizontal">
					<div class="form-group">
						<label for="total-views3" class="sr-only control-label" ></label>
						<div class="col-xs-12">
							<input type="text" class="form-control" id="total-views3" placeholder="本文主题">
						</div>
						<div class="remove"><i class="fa fa-times"></i></div>
					</div>
					<div class="form-group">
						<label for="first-view3" class="col-xs-1 control-label"><span>1.</span></label>
						<div class="col-xs-11">
							<input type="text" class="form-control" id="first-view3" placeholder="第一方面">
						</div>
						<div class="remove"><i class="fa fa-times"></i></div>
					</div>
					<div class="form-group">
						<label for="second-view3" class="col-xs-1 control-label"><span>2.</span></label>
						<div class="col-xs-11">
							<input type="text" class="form-control" id="second-view3" placeholder="第二方面">
						</div>
						<div class="remove"><i class="fa fa-times"></i></div>
					</div>
					<div class="form-group">
						<label for="third-view3" class="col-xs-1 control-label"><span>3.</span></label>
						<div class="col-xs-11">
							<input type="text" class="form-control" id="third-view3" placeholder="第三方面">
						</div>
						<div class="remove"><i class="fa fa-times"></i></div>
					</div>
				</form>
			</div>
		</div>
		<div class="col-xs-7 write-text write-ari">
			<?php
			if($write_content['class_name']=='综合写作')
			{
				echo $write_content['reading_content'];
			}
			elseif($write_content['class_name']=='独立写作')
			{
				echo $write_content['question'];
			}
			?>
		</div>
	</div>
</div>
<div class="add-note hidden">
    <div class="row">
        <div class="col-xs-7 text-note"></div>
        <div class="col-xs-5 add-note-text">+加到笔记</div>
    </div>
    <div class="row addtoleft">
        <div class="col-xs-8 add-left">+添加到左侧答案栏</div>
    </div>
</div>
</div>
<div class="addnote">
    <div class="note-lead">
        <span id="note-word">笔记</span>
        <span class="close"><i class="fa fa-times"></i></span>
    </div>
    <div class="note-text">
        <div contenteditable="true" id="note-self"><?=HtmlPurifier::process($my_note['note']);?></div>
    </div>
    <form action="#" id="note-form">
        <button type="button" name="note-save" id="note-submit">Save and Close</button>
        <input type="hidden" name="saved-note" value="">
    </form>
</div>